package com.boarsoft.boar.soagov.monitor;

import org.springframework.beans.factory.annotation.Autowired;

import com.boarsoft.boar.app.AppInstBiz;
import com.boarsoft.boar.deploy.plan.bean.BuildRequest;
import com.boarsoft.boar.deploy.service.DeployService;
import com.boarsoft.boar.entity.AppInst;
import com.boarsoft.flow.core.bean.ProcessHandler;
import com.boarsoft.soagov.bean.MonitorData;

public class AppInstDownPH implements ProcessHandler {
	@Autowired
	protected AppInstBiz appInstBiz;
	@Autowired
	protected DeployService deploySvc;

	protected String planId;

	@Override
	public Object process(String entry, Object data, Throwable throwable) throws Throwable {
		MonitorData md = (MonitorData) data;
		// InstanceDown
		AppInst ai = appInstBiz.find(md.getIp(), md.getPort());
		ai.setStatus(AppInst.STATUS_FAILED);
		appInstBiz.update(ai);
		// 调起预置的部署计划
		BuildRequest bp = new BuildRequest();
		bp.setEnv(ai.getEnv());
		// p.setId(id);
		bp.setPlanId(planId);
		// p.setToken(token);
		// p.setWssid(wssid);
		bp.put("inst1", ai);
		deploySvc.execute(bp);
		return data;
	}

	public String getPlanId() {
		return planId;
	}

	public void setPlanId(String planId) {
		this.planId = planId;
	}
}